package com.example.arithmeticleetcode.leetcode;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-06-12 16:49
 **/
public class Demo28 {

    public static void main(String[] args) {
        int[] A = {1, 2, 3, 4};
        int[][] queries = {{1, 0}, {-3, 1}, {-4, 0}, {2, 3}};
        int[] arr = sumEvenAfterQueries(A, queries);
        for (int i : arr) {
            System.out.println(i);
        }

        System.out.println("switch start,,,");
        switch (6) {
            case 1:
                System.out.println("===1");
                break;
            case 2:
                System.out.println("===2");
                break;
        }
        System.out.println("switch end,,,");
    }

    public static int[] sumEvenAfterQueries(int[] A, int[][] queries) {
        int[] arr = new int[A.length];
        int count = 0;
        int sum = 0;
        for (int i : A) {
            if (i % 2 == 0) {
                sum += i;
            }
        }
        int init = 0;
        for (int[] query : queries) {
            init = A[query[1]];
            //偶数为true
            boolean flag = false;
            if (init % 2 == 0) {
                flag = true;
            }
            A[query[1]] = init + query[0];
            System.out.println(A[query[1]]);
            //变后的偶数
            if (A[query[1]] % 2 == 0) {
                //偶数=true
                if (flag) {
                    sum = sum - init + A[query[1]];
                } else {
                    sum = sum + A[query[1]];
                }
            }
            //变后的奇数
            else {
                //偶数=true
                if (flag) {
                    sum = sum - init;
                }
            }
            arr[count] = sum;
            count++;
        }
        return arr;
    }
}
